﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Pantry.Business;
using Pantry.Commons;

namespace Pantry.Web.Users.Controls
{
    public delegate void SendPostCodeToPage(string values);
    public partial class ListPostcode : System.Web.UI.UserControl
    {
        public event SendPostCodeToPage sendPostcodeToPage;
        protected void Page_Load(object sender, EventArgs e)
        {
            LoadAllPostCode();
        }
        protected void LoadAllPostCode()
        {
            var countiesBus = new CountyBus();
            var counties = countiesBus.SelectAllCounty();
            CollectionPager.PageSize = ConstantSetup.PostCodePageSize;
            CollectionPager.BindToControl = RepeaterBusiness;
            CollectionPager.DataSource = counties.DefaultView;
            RepeaterBusiness.DataSource = CollectionPager.DataSourcePaged;
            RepeaterBusiness.DataBind();
        }
        protected void ButtonSelectClick(object sender, EventArgs e)
        {

            if (!string.IsNullOrEmpty(HttpHelper.GetFormString("RadioPostcode")))
            {
                string postCodeValues = HttpHelper.GetFormString("RadioPostcode");
                if (sendPostcodeToPage != null)
                {
                    sendPostcodeToPage(postCodeValues);
                }
                ScriptManager.RegisterStartupScript(UpdatePanel1, GetType(), "Key", "ClosePostcodePopup()", true);
            }
            else
            {
                ScriptManager.RegisterStartupScript(this, GetType(), "YourUniqueScriptKey", "alert('Please select one row !');", true);
            }
        }
    }
}